package bpmjs;

import bpmjs.Event;
import bpmjs.DomEventDispatcher;
import bpmjs.HtmlDef;

import js.Dom;

class MooToolsAdapter
{
    public static function getContext2D(canvas : Canvas) : CanvasRenderingContext2D
    {
        return canvas.getContext("2d");
    }
    
    public static function createCanvas(document : Document) : Canvas
    {
    	var canvas : Canvas = cast document.createElement("canvas");
    	MooToolsAdapter.setStyle(canvas, "position", "absolute");
        return canvas;
    }
    
    public static function createDiv(document : Document) : HtmlDom
    {
    	var div = document.createElement("div");
    	MooToolsAdapter.setStyle(div, "position", "absolute");
        return div;
    }
    
    public static function createImage(document : Document) : Image
    {
    	var image : Image = untyped __js__("new Image()");
    	MooToolsAdapter.setStyle(image, "position", "absolute");
        return image;
    }
    
    public static function createAnchor(document : Document) : bpmjs.Anchor
    {
    	var anchor : bpmjs.Anchor = cast document.createElement("a");
    	MooToolsAdapter.setStyle(anchor, "position", "absolute");
        return anchor;
    }
    
    public static inline function setStyle(domElement : HtmlDom, property : String, value : String) : Void
    {
       untyped domElement.setStyle(property, value);
    }
    
    public static function addEventListener(domElement : HtmlDom, type : String, handler : Event->Void)
    {
    	var dispatcher : DomEventDispatcher = DomEventDispatcher.lazyInit(domElement);
		dispatcher.addEventListener(type, handler);
    }
}
